package com.bidevalution.controller.api;

import com.bidevalution.business.service.BeSectionEnterpriseService;
import com.bidevalution.dao.entity.BeSectionDecrypt;
import com.bidevalution.dao.entity.BeSectionEnterprise;
import com.bidevalution.support.context.Constants;
import com.qtp.common.core.TSUser;
import com.qtp.core.model.Response;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by glodon on 2019-09-05.
 */
@Log4j2
@RestController
@RequestMapping("/beSectionEnterprise")
@Api(tags = "标段投标单位信息")
public class BeSectionEnterpriseController extends BaseController {
    @Autowired
    private BeSectionEnterpriseService beSectionEnterpriseService;

    /**
     * 技术标为暗标的，生成暗标号
     * @param sectionId 标段Id
     * @return
     */
    @PostMapping("/generateHideNumber")
    @ApiOperation(value = "技术标为暗标的，生成暗标号", response = String.class)
    @ApiImplicitParams(
    {
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "sectionId", value = "标段主键", required = true),
    })
    public Response<String> generateHideNumber(@RequestParam("sectionId")String sectionId) {
        try {
            return Response.ok(beSectionEnterpriseService.generateHideNumber(sectionId));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Response.fail(e.getMessage());
        }
    }

    /**
     * 根据标段id获取投标单位列表
     *
     * @param sectionId
     * @return
     */
    @GetMapping("/queryEnterBySectionId")
    @ApiOperation(value = "根据标段id获取投标单位列表(2019-09-17-v1)", response = BeSectionEnterprise.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sectionId", value = "标段id", dataType = "String", paramType = "query", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = Constants.FIVE_HUNDRED_AND_ONE, message = "参数不可以为空"),
            @ApiResponse(code = Constants.FIVE_HUNDRED_AND_TWO, message = "获取投标单位列表失败"),
    })
    public Response queryEnterBySectionId(@RequestParam("sectionId") String sectionId) {
        if (StringUtils.isBlank(sectionId)) {
            Response.fail("参数不可以为空", Constants.FIVE_HUNDRED_AND_ONE);
        }
        try {
            return Response.ok(beSectionEnterpriseService.getEnterpriseNames(sectionId));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Response.fail("获取投标单位列表失败", Constants.FIVE_HUNDRED_AND_TWO);
        }
    }
}
